﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Resources;
using System.Text;
using System.Threading.Tasks;

namespace Nantianmen.Shared
{
    public class NantianmenErrorDescriber
    {
        public static NantianmenError DuplicateClusterId(string? id)
        {
            return new NantianmenError
            {
                Code = nameof(DuplicateClusterId),
                Description = id is null
                        ? Resource.DuplicateClusterId
                        : string.Format(CultureInfo.InvariantCulture, "{0}, {1}", Resource.DuplicateClusterId, id)
            };
        }

        public NantianmenError ClusterAlreadyHasDestination(string destinationId)
        {
            return new NantianmenError
            {
                Code = nameof(ClusterAlreadyHasDestination),
                Description = string.Format(CultureInfo.InvariantCulture,
                    Resource.DestinationAlreadyInCluster, destinationId)
            };
        }

        public NantianmenError ClusterIdFormatIsInvalid(string rightPattern)
        {
            return new NantianmenError
            {
                Code = nameof(ClusterIdFormatIsInvalid),
                Description = string.Format(CultureInfo.InvariantCulture, Resource.ClusterIdFormartIsInvalid, rightPattern)
            };
        }

        public NantianmenError ClusterIdMustNotNullAndNotWhiteSpace()
        {
            return new NantianmenError
            {
                Code = nameof(ClusterIdMustNotNullAndNotWhiteSpace),
                Description = Resource.ClusterIdMustNotNullAndNotWhiteSpace
            };
        }

        public NantianmenError ClusterNotHasDestination(string destinationId)
        {
            return new NantianmenError
            {
                Code = nameof(ClusterNotHasDestination),
                Description = string.Format(CultureInfo.InvariantCulture,
                    Resource.DestinationNotInCluster, destinationId)
            };
        }

        public virtual NantianmenError DefaultError()
        {
            return new NantianmenError
            {
                Code = nameof(DefaultError),
                Description = Resource.DefaultError
            };
        }

        public NantianmenError ClusterNotFound(string clusterId)
        {
            return new NantianmenError
            {
                Code = nameof(ClusterNotFound),
                Description = string.Format(CultureInfo.InvariantCulture, Resource.ClusterNotFound, clusterId)
            };
        }

        public NantianmenError DuplicateRouteId(string routeId)
        {
            return new NantianmenError
            {
                Code = nameof(DuplicateRouteId),
                Description = string.Format(CultureInfo.InvariantCulture, Resource.DuplicateRouteId, routeId)
            };
        }

        public NantianmenError RouteIdMustNotNullAndNotWhiteSpace()
        {
            return new NantianmenError
            {
                Code = nameof(RouteIdMustNotNullAndNotWhiteSpace),
                Description = Resource.RouteIdMustNotNullAndNotWhiteSpace
            };
        }

        public NantianmenError RouteNotFound(string routeId)
        {
            return new NantianmenError
            {
                Code = nameof(RouteNotFound),
                Description = string.Format(CultureInfo.InvariantCulture, Resource.RouteNotFound, routeId)
            };
        }
    }
}
